﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BHXH.Core.IService;
using FX.Core;
using CRM.Admin;
using BHXH.Core.Domain;
using NHibernate.Cfg;
using NHibernate;
using System.Text.RegularExpressions;


namespace BHXH.Frm.Frm
{

    public partial class ThayDoiThongTinTK : Form
    {
        private readonly IthongtincongtyService _thongtincongtySrv;
        private readonly ItaikhoanService _taikhoanSrv;
        string TenDangNhap = "";
        string matkhau = "";
        string hoten = "";
        string email = "";
        string congtyid = "";
        string taikhoanid = "";
        public ThayDoiThongTinTK()
        {
            InitializeComponent();
            _thongtincongtySrv = IoC.Resolve<IthongtincongtyService>();
            _taikhoanSrv = IoC.Resolve<ItaikhoanService>();
        }

        public ThayDoiThongTinTK(string TenDN, string MatKhau, string HoTen, string Email, string CongTyID, string TaiKhoanID)
        {
            InitializeComponent();
            _thongtincongtySrv = IoC.Resolve<IthongtincongtyService>();
            _taikhoanSrv = IoC.Resolve<ItaikhoanService>();
            TenDangNhap = TenDN;
            matkhau = MatKhau;
            hoten = HoTen;
            email = Email;
            congtyid = CongTyID;
            taikhoanid = TaiKhoanID;
        }

        private void ThayDoiThongTinTK_Load(object sender, EventArgs e)
        {
            LoadThongTinTK();
        }

        public void LoadThongTinTK()
        {
            txtTenDangNhap.Text = TenDangNhap;
            txtHoTen.Text = hoten;
            txtMatKhau.Text = "";
            txtEmail.Text = email;
        }



        private void btnLuu_Click(object sender, EventArgs e)
        {
            thongtincongty ttct = new thongtincongty();
            taikhoan tk = new taikhoan();
            if (txtMatKhau.Text == "")
            {
                ttct.ID = int.Parse(congtyid);
                ttct.Email = txtEmail.Text;
                ttct.TenCongTy = txtHoTen.Text;
                tk.MatKhau = matkhau;
                tk.ID = int.Parse(taikhoanid);
                if (_thongtincongtySrv.UpdateTen_EmailDonVi(ttct) > 0 && _taikhoanSrv.Update_MatKhauTaiKhoan(tk) > 0)
                {
                    MessageBox.Show("Sửa thông tin thành công");
                }
            }
            else
            {
                ttct.ID = int.Parse(congtyid);
                ttct.Email = txtEmail.Text;
                ttct.TenCongTy = txtHoTen.Text;
                tk.ID = int.Parse(taikhoanid);
                tk.MatKhau = txtMatKhau.Text;
                if (_thongtincongtySrv.UpdateTen_EmailDonVi(ttct) > 0 && _taikhoanSrv.Update_MatKhauTaiKhoan(tk) > 0)
                {
                    MessageBox.Show("Sửa thông tin thành công");
                }
            }
            
        }

        private void ThayDoiThongTinTK_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("Bạn có chắc chắn thoát không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                this.Dispose();
            }
            else
            {
                return;
            }
        }

    }
}
